//early life and other instruments
clear
clear matrix
clear mata
cap log close
************************************************************************************
* DIRECTORY ROADMAP
sysdir set PLUS C:\ado\plus\c

global dir1 C:\Users\hab55\Dropbox\Second_paper_Ghana\2023_EDCC_Price\Data
global dir2 C:\Users\hab55\Dropbox\Second_paper_Ghana\2023_EDCC_Price\Do
global dir3 C:\Users\hab55\Dropbox\Second_paper_Ghana\2023_EDCC_Price\Output


clear
///////////////////////////////////////////////////////////////////////

***Table D.2:

***Grade outcome 

use "$dir1\grade_other_instruments_data", clear
///early life analysis 
//event IVS
//second stage 
ivreg2  years_school    (Y0_1=Z0_d_early  Z0_f_early Z0_e_early Z0_w_early )  gender genderhd i.agey i.ROB#c.YOB i.ROB i.YOB  i.year [aw=weight],  cluster (ROB)  
boottest Y0_1=0 ,    nograph   
gen smpl_1=0
replace smpl_1=1 if e(sample)==1
outreg2 using "$dir3\early_life_IV.tex", keep(Y0_1 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)
////////////////////////////////////////////////////////////////////////////////
//first stage 
reghdfe Y0_1  Z0_d_early  Z0_f_early Z0_e_early Z0_w_early   gender genderhd i.ROB#c.YOB i.agey i.year   [aw=weight] if smpl_1==1 , a(ROB YOB) cluster (ROB)
outreg2 using "$dir3\earllife_firststage.tex", keep( Z0_d_early  Z0_f_early Z0_e_early Z0_w_early  ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

///Weather IVS
//second stage 
ivreg2  years_school    (Y0_1=Z0_rain_early_ano Z0_temp_early_ano)  gender genderhd  i.agey i.ROB#c.YOB i.ROB i.YOB i.year  [aw=weight],  cluster (ROB)
boottest Y0_1=0 ,  nograph  
gen smpl_2=0
replace smpl_2=1 if e(sample)==1  
outreg2 using "$dir3\early_life_IV.tex", keep(Y0_1 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)
///////////////////////////////////////////////////////////////////////////////
//first stage 
reghdfe Y0_1  Z0_rain_early_ano Z0_temp_early_ano gender genderhd i.ROB#c.YOB  i.agey i.year  [aw=weight] if smpl_2==1, a(ROB YOB) cluster (ROB)

outreg2 using "$dir3\earllife_firststage1.tex", keep(Z0_rain_early_ano Z0_temp_early_ano  ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)
/////////////////////////////////////////////////////////////////////////////////
///inutero analysis 
//event IVs

//second stage 
ivreg2  years_school (Y0=Z0_d_1  Z0_e_1 Z0_f_1 Z0_w_1  )  gender genderhd  i.agey i.ROB#c.YOB i.ROB i.YOB i.year [aw=weight],  cluster (ROB) 
boottest Y0=0 ,    nograph  
gen smpl_3=0
replace smpl_3=1 if e(sample)==1 
outreg2 using "$dir3\inutero_IV.tex", keep(Y0 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)
///////////////////////////////////////////////////////////////////////////////
///first stage 
reghdfe Y0  Z0_d_1  Z0_e_1 Z0_f_1 Z0_w_1   gender genderhd i.ROB#c.YOB i.agey i.year  [aw=weight] if smpl_3==1 , a(ROB YOB) cluster (ROB) 
outreg2 using "$dir3\inutero_firststage.tex", keep(Z0_d_1  Z0_e_1 Z0_f_1 Z0_w_1 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)
//////////////////////////////////////////////////////////////////////////////
////weather IVs
// second stage 
ivreg2  years_school (Y0=Z0_rain_ano Z0_temp_ano)  gender genderhd  i.agey i.ROB#c.YOB i.ROB i.YOB i.year [aw=weight], cluster (ROB) 
boottest Y0=0 ,    nograph  
gen smpl_4=0
replace smpl_4=1 if e(sample)==1 
outreg2 using "$dir3\inutero_IV.tex", keep(Y0 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)
////////////////////////////////////////////////////////////////////////////////////
///first stage 
reghdfe Y0  Z0_rain_ano Z0_temp_ano  gender genderhd i.ROB#c.YOB i.agey i.year  [aw=weight] if smpl_4==1, a(ROB YOB) cluster (ROB) 
outreg2 using "$dir3\inutero_firststage1.tex", keep(Z0_rain_ano Z0_temp_ano  ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)
//////////////////////////////////////////////////////////////////////////

///Raven/IQ
use "$dir1\cognitive_raven_other_instruments_data", clear

///early life
///event IVs
// second stage 
ivreg2  raven    (Y0_1=Z0_d_early  Z0_f_early Z0_e_early Z0_w_early  ) gender head_gender i.ageyears  i.ROB#c.YOB  i.ROB i.YOB i.year, cluster(ROB)  
boottest Y0_1=0 ,   nograph  
gen smpl_1=0
replace smpl_1=1 if e(sample)==1
outreg2 using "$dir3\early_life_IV.tex", keep(Y0_1 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)
///////////////////////////////////////////////////////////////////////////////
//first stage 
reghdfe Y0_1  Z0_d_early  Z0_f_early Z0_e_early Z0_w_early   gender head_gender i.ageyears i.ROB#c.YOB i.year if smpl_1==1, a(ROB YOB) cluster(ROB)

outreg2 using "$dir3\earllife_firststage.tex", keep( Z0_d_early  Z0_f_early Z0_e_early Z0_w_early  ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)
//////////////////////////////////////////////////////////////////////////////
////weather IVs
// second stage 
ivreg2  raven    (Y0_1=Z0_rain_early_ano Z0_temp_early_ano) gender head_gender i.ageyears  i.ROB#c.YOB  i.ROB i.YOB i.year, cluster(ROB)  
boottest Y0_1=0 ,   nograph  
gen smpl_2=0
replace smpl_2=1 if e(sample)==1
outreg2 using "$dir3\early_life_IV.tex", keep(Y0_1 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)
///////////////////////////////////////////////////////////////////////////////////////

//first stage 
reghdfe Y0_1  Z0_rain_early Z0_temp_early  gender head_gender i.ageyears i.ROB#c.YOB i.year if smpl_2==1, a(ROB YOB) cluster(ROB)
outreg2 using "$dir3\earllife_firststage1.tex", keep( Z0_rain_early Z0_temp_early ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)
///////////////////////////////////////////////////////////////////////////////
//inutero

//event IVs
// second stage 
ivreg2   raven (Y0=Z0_d_1  Z0_e_1 Z0_f_1 Z0_w_1 )  gender head_gender i.ageyears  i.ROB#c.YOB  i.ROB i.YOB i.year, cluster(ROB)  
boottest Y0=0 ,    nograph  
gen smpl_3=0
replace smpl_3=1 if e(sample)==1
outreg2 using "$dir3\inutero_IV.tex", keep(Y0 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)
///////////////////////////////////////////////////////////////////////////////
//first stage 
reghdfe Y0  Z0_d_1  Z0_e_1 Z0_f_1 Z0_w_1  gender head_gender i.ROB#c.YOB i.ageyears i.year if smpl_3==1 , ab(ROB YOB) cluster(ROB)

outreg2 using "$dir3\inutero_firststage.tex", keep(Z0_d_1  Z0_e_1 Z0_f_1 Z0_w_1 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)
////////////////////////////////////////////////////////////////////////////////
//weather IVs

// second stage 
ivreg2  raven (Y0=Z0_rain_ano Z0_temp_ano)  gender head_gender  i.ageyears  i.ROB#c.YOB  i.ROB i.YOB i.year, cluster(ROB)  
boottest Y0=0 ,  nograph  
gen smpl_4=0
replace smpl_4=1 if e(sample)==1
outreg2 using "$dir3\inutero_IV.tex", keep(Y0 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)
///////////////////////////////////////////////////////////////////////////////
///first stage 
reghdfe Y0  Z0_rain_ano Z0_temp_ano gender head_gender i.ROB#c.YOB i.ageyears i.year if smpl_4==1 , ab(ROB YOB) cluster(ROB)
outreg2 using "$dir3\inutero_firststage1.tex", keep(Z0_rain_ano Z0_temp_ano ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)
*******************************************************************************
*********************************************************************************